/**
 */

package com.tianpengtech.front.web.passport;

import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;
import com.jfinal.validate.Validator;
import com.tianpengtech.common.util.IpKit;
import com.tianpengtech.front.mobile.common.constant.Constant;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * RegValidator 验证注册表单，并且判断邮箱、昵称是否已被注册
 */
public class AuthValidator extends Validator {
	private static final PassportService srv = PassportService.me;

	protected void validate(Controller c) {
		if ("POST".equals(c.getRequest().getMethod().toUpperCase())){
			validateRequired("authenticate.company_name", "companyNameMsg", "公司名称不能为空");
			validateRequired("authenticate.company_address", "companyAddressMsg", "公司地址不能为空");
			validateRequired("authenticate.company_charge", "companyChargeMsg", "法人姓名不能为空");
			validateRequired("authenticate.company_charge_phone", "chargePhoneMsg", "法人手机号码不能为空");
			validateRequired("authenticate.company_license", "licenseMsg", "法人手机号码不能为空");
			validateRequired("authenticate.legal_idcard_front", "idcardFrontMsg", "法人手机号码不能为空");
			validateRequired("authenticate.legal_idcard_tails", "idcardTailsMsg", "法人手机号码不能为空");
			validateRequired("authenticate.charge_card", "chargeCardMsg", "法人手机号码不能为空");
			validateRegex("authenticate.company_charge_phone", Constant.REGEX_MOBILE,"chargePhoneMsg","法人手机号码格式不正确");
		}
	}

	protected void handleError(Controller c) {
		c.render("auth_form.html");
	}

	private String getUpDir(){
		SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMDD");
		return "/"+sdf.format(new Date());
	}

}

